Page({
	data: {
		params: {
			loginId: ''
		},
		isShowPhone: false,
	},
	onLoad: function() {

	},
	
	getPhoneNumber(e) {
		const that = this;
		const {
			encryptedData,
			iv,
			signature,
			rawData
		} = e.detail;
		wx.login({
			success(res) {
				if (res.code) {
					wx.request({
						url: "https://pms.uxon.net/api/wx/user/getPhoneNumber",
						method: "POST",
						data: {
							...that.data.params,
							code: res.code,
							encryptedData,
							iv,
						},
						header: {
							'content-type': 'application/x-www-form-urlencoded', //修改此处即可
						},
						success(res) {
							wx.setStorageSync('userInfo', { ...wx.getStorageSync('userInfo'),
								phoneNumber: res.data.data.phoneNumber
							})
							wx.navigateBack({
								delta: 1
							})
						},
					});
				} else {
					console.log("登录失败！" + res.errMsg);
				}
			},
		});

	},
	getUserInfo(e) {
		const {
			encryptedData,
			iv,
			signature,
			rawData
		} = e.detail;
		const that = this;
		wx.login({
			success(res) {
				if (res.code) {
					const params = {
						appid: "wx90ed8918c4766d32",
						code: res.code,
						encryptedData,
						iv,
						rawData,
						signature,
					};
					wx.request({
						url: "https://pms.uxon.net/api/wx/user/login", //仅为示例，并非真实的接口地址
						method: "POST",
						data: params,
						header: {
							'content-type': 'application/x-www-form-urlencoded', //修改此处即可
						},
						success(res) {
							that.setData({
								params: { ...params,
									loginId: res.data.data.loginId
								},
								isShowPhone: true,
							})
							wx.setStorageSync('userInfo', res.data.data)
						},
					});
				} else {
					console.log("登录失败！" + res.errMsg);
				}
			},
		});
	},
})
